<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //sum(1)(2)(3)(4)
        //sum(1,2,3,4)
        //sum(1)(2)(3,4)
        const nums = []
        function sum(...args) {
            nums.push(...args)
            if (nums.length >= 5) {
                return nums.slice(0, 5).reduce((a, b) => a + b, 0)
                nums = []
            }
            else {
                return sum
            }
        }
        // console.log(sum(1)(2)(3)(4)(5))
        // console.log(sum(1)(15)(4)(5)(6))
    </script>
</body>

</html>